package com.googlecode.dgwt.client.dojox.data.model.base;

import java.util.Collection;

import com.googlecode.dgwt.client.dojo.data.model.StoreModelBase;


/**
 * @author      Wellington Tadeu dos Santos
 * @since       DGWT v0.01
 */
public abstract class NamedModelBase<Item,Column extends NamedColumn<Item,?>> extends StoreModelBase<Item,Column> implements NamedModel<Item,Column> {


    public NamedModelBase() {
        super();
    }

    public NamedModelBase(int capacity) {
        super(capacity);
    }

    public NamedModelBase(Collection<? extends Column> columnList) {
        super(columnList);
    }

    @Override
    public Column findColumn(String name) {
        for (Column column : getColumns()) {
            if (column.getName().equals(name)) {
                return column;
            }
        }
        return null;
    }

    @Override
    public int indexOfColumn(String name) {
        int index = 0;
        for (Column column : getColumns()) {
            if (column.getName().equals(name)) {
                return index;
            }
            index++;
        }
        return -1;
    }
    
}
